<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QStylePainter Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QStylePainter Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QStylePainter class is a convenience class for drawing
<a href="qstyle.html">QStyle</a> elements inside a widget. <a href="#details">More...</a></p>

<p>Inherits <a href="qpainter.html">QPainter</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qstylepainter.html#QStylePainter">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qstylepainter.html#QStylePainter-2">__init__</a></b> (<i>self</i>, QWidget&#160;<i>w</i>)</li><li><div class="fn" /><b><a href="qstylepainter.html#QStylePainter-3">__init__</a></b> (<i>self</i>, QPaintDevice&#160;<i>pd</i>, QWidget&#160;<i>w</i>)</li><li><div class="fn" />bool <b><a href="qstylepainter.html#begin">begin</a></b> (<i>self</i>, QWidget&#160;<i>w</i>)</li><li><div class="fn" />bool <b><a href="qstylepainter.html#begin-2">begin</a></b> (<i>self</i>, QPaintDevice&#160;<i>pd</i>, QWidget&#160;<i>w</i>)</li><li><div class="fn" /><b><a href="qstylepainter.html#drawComplexControl">drawComplexControl</a></b> (<i>self</i>, QStyle.ComplexControl&#160;<i>cc</i>, QStyleOptionComplex&#160;<i>opt</i>)</li><li><div class="fn" /><b><a href="qstylepainter.html#drawControl">drawControl</a></b> (<i>self</i>, QStyle.ControlElement&#160;<i>ce</i>, QStyleOption&#160;<i>opt</i>)</li><li><div class="fn" /><b><a href="qstylepainter.html#drawItemPixmap">drawItemPixmap</a></b> (<i>self</i>, QRect&#160;<i>r</i>, int&#160;<i>flags</i>, QPixmap&#160;<i>pixmap</i>)</li><li><div class="fn" /><b><a href="qstylepainter.html#drawItemText">drawItemText</a></b> (<i>self</i>, QRect&#160;<i>rect</i>, int&#160;<i>flags</i>, QPalette&#160;<i>pal</i>, bool&#160;<i>enabled</i>, QString&#160;<i>text</i>, QPalette.ColorRole&#160;<i>textRole</i>&#160;=&#160;QPalette.NoRole)</li><li><div class="fn" /><b><a href="qstylepainter.html#drawPrimitive">drawPrimitive</a></b> (<i>self</i>, QStyle.PrimitiveElement&#160;<i>pe</i>, QStyleOption&#160;<i>opt</i>)</li><li><div class="fn" />QStyle <b><a href="qstylepainter.html#style">style</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QStylePainter class is a convenience class for drawing
<a href="qstyle.html">QStyle</a> elements inside a widget.</p>
<p>QStylePainter extends <a href="qpainter.html">QPainter</a> with
a set of high-level <tt>draw...()</tt> functions implemented on top
of <a href="qstyle.html">QStyle</a>'s API. The advantage of using
QStylePainter is that the parameter lists get considerably shorter.
Whereas a <a href="qstyle.html">QStyle</a> object must be able to
draw on any widget using any painter (because the application
normally has one <a href="qstyle.html">QStyle</a> object shared by
all widget), a QStylePainter is initialized with a widget,
eliminating the need to specify the <a href="qwidget.html">QWidget</a>, the <a href="qpainter.html">QPainter</a>, and the <a href="qstyle.html">QStyle</a> for every function call.</p>
<p>Example using <a href="qstyle.html">QStyle</a> directly:</p>
<pre class="cpp">
 <span class="type">void</span> MyWidget<span class="operator">.</span>paintEvent(<span class="type"><a href="qpaintevent.html">QPaintEvent</a></span> <span class="operator">*</span> <span class="comment">/* event */</span>)
 {
     <span class="type"><a href="qpainter.html">QPainter</a></span> painter(<span class="keyword">this</span>);

     <span class="type"><a href="qstyleoptionfocusrect.html">QStyleOptionFocusRect</a></span> option;
     option<span class="operator">.</span>initFrom(<span class="keyword">this</span>);
     option<span class="operator">.</span>backgroundColor <span class="operator">=</span> palette()<span class="operator">.</span>color(<span class="type"><a href="qpalette.html">QPalette</a></span><span class="operator">.</span>Background);

     style()<span class="operator">-</span><span class="operator">&gt;</span>drawPrimitive(<span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">.</span>PE_FrameFocusRect<span class="operator">,</span> <span class="operator">&amp;</span>option<span class="operator">,</span> <span class="operator">&amp;</span>painter<span class="operator">,</span> <span class="keyword">this</span>);
 }
</pre>
<p>Example using QStylePainter:</p>
<pre class="cpp">
 <span class="type">void</span> MyWidget<span class="operator">.</span>paintEvent(<span class="type"><a href="qpaintevent.html">QPaintEvent</a></span> <span class="operator">*</span> <span class="comment">/* event */</span>)
 {
     <span class="type">QStylePainter</span> painter(<span class="keyword">this</span>);

     <span class="type"><a href="qstyleoptionfocusrect.html">QStyleOptionFocusRect</a></span> option;
     option<span class="operator">.</span>initFrom(<span class="keyword">this</span>);
     option<span class="operator">.</span>backgroundColor <span class="operator">=</span> palette()<span class="operator">.</span>color(<span class="type"><a href="qpalette.html">QPalette</a></span><span class="operator">.</span>Background);

     painter<span class="operator">.</span>drawPrimitive(<span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">.</span>PE_FrameFocusRect<span class="operator">,</span> option);
 }
</pre><hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QStylePainter" />QStylePainter.__init__ (<i>self</i>)</h3><p>Constructs a <a href="qstylepainter.html">QStylePainter</a>.</p>


<h3 class="fn"><a name="QStylePainter-2" />QStylePainter.__init__ (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>w</i>)</h3><p>Construct a <a href="qstylepainter.html">QStylePainter</a> using
widget <i>widget</i> for its paint device.</p>


<h3 class="fn"><a name="QStylePainter-3" />QStylePainter.__init__ (<i>self</i>, <a href="qpaintdevice.html">QPaintDevice</a>&#160;<i>pd</i>, <a href="qwidget.html">QWidget</a>&#160;<i>w</i>)</h3><p>Construct a <a href="qstylepainter.html">QStylePainter</a> using
<i>pd</i> for its paint device, and attributes from
<i>widget</i>.</p>


<h3 class="fn"><a name="begin" />bool QStylePainter.begin (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>w</i>)</h3><p>Begin painting operations on the specified <i>widget</i>.
Returns true if the painter is ready to use; otherwise returns
false.</p>
<p>This is automatically called by the constructor that takes a
<a href="qwidget.html">QWidget</a>.</p>


<h3 class="fn"><a name="begin-2" />bool QStylePainter.begin (<i>self</i>, <a href="qpaintdevice.html">QPaintDevice</a>&#160;<i>pd</i>, <a href="qwidget.html">QWidget</a>&#160;<i>w</i>)</h3><p>This is an overloaded function.</p>
<p>Begin painting operations on paint device <i>pd</i> as if it was
<i>widget</i>.</p>
<p>This is automatically called by the constructor that takes a
<a href="qpaintdevice.html">QPaintDevice</a> and a <a href="qwidget.html">QWidget</a>.</p>


<h3 class="fn"><a name="drawComplexControl" />QStylePainter.drawComplexControl (<i>self</i>, <a href="qstyle.html#ComplexControl-enum">QStyle.ComplexControl</a>&#160;<i>cc</i>, <a href="qstyleoptioncomplex.html">QStyleOptionComplex</a>&#160;<i>opt</i>)</h3><p>Use the widget's style to draw a complex control <i>cc</i>
specified by the <a href="qstyleoptioncomplex.html">QStyleOptionComplex</a>
<i>option</i>.</p>
<p><b>See also</b> <a href="qstyle.html#drawComplexControl">QStyle.drawComplexControl</a>().</p>


<h3 class="fn"><a name="drawControl" />QStylePainter.drawControl (<i>self</i>, <a href="qstyle.html#ControlElement-enum">QStyle.ControlElement</a>&#160;<i>ce</i>, <a href="qstyleoption.html">QStyleOption</a>&#160;<i>opt</i>)</h3><p>Use the widget's style to draw a control element <i>ce</i>
specified by <a href="qstyleoption.html">QStyleOption</a>
<i>option</i>.</p>
<p><b>See also</b> <a href="qstyle.html#drawControl">QStyle.drawControl</a>().</p>


<h3 class="fn"><a name="drawItemPixmap" />QStylePainter.drawItemPixmap (<i>self</i>, <a href="qrect.html">QRect</a>&#160;<i>r</i>, int&#160;<i>flags</i>, <a href="qpixmap.html">QPixmap</a>&#160;<i>pixmap</i>)</h3><p>Draws the <i>pixmap</i> in rectangle <i>rect</i>. The pixmap is
aligned according to <i>flags</i>.</p>
<p><b>See also</b> <a href="qstyle.html#drawItemPixmap">QStyle.drawItemPixmap</a>() and
<a href="qt.html#AlignmentFlag-enum">Qt.Alignment</a>.</p>


<h3 class="fn"><a name="drawItemText" />QStylePainter.drawItemText (<i>self</i>, <a href="qrect.html">QRect</a>&#160;<i>rect</i>, int&#160;<i>flags</i>, <a href="qpalette.html">QPalette</a>&#160;<i>pal</i>, bool&#160;<i>enabled</i>, QString&#160;<i>text</i>, <a href="qpalette.html#ColorRole-enum">QPalette.ColorRole</a>&#160;<i>textRole</i>&#160;=&#160;QPalette.NoRole)</h3><p>Draws the <i>text</i> in rectangle <i>rect</i> and palette
<i>pal</i>. The text is aligned and wrapped according to
<i>flags</i>.</p>
<p>The pen color is specified with <i>textRole</i>. The
<i>enabled</i> bool indicates whether or not the item is enabled;
when reimplementing this bool should influence how the item is
drawn.</p>
<p><b>See also</b> <a href="qstyle.html#drawItemText">QStyle.drawItemText</a>() and <a href="qt.html#AlignmentFlag-enum">Qt.Alignment</a>.</p>


<h3 class="fn"><a name="drawPrimitive" />QStylePainter.drawPrimitive (<i>self</i>, <a href="qstyle.html#PrimitiveElement-enum">QStyle.PrimitiveElement</a>&#160;<i>pe</i>, <a href="qstyleoption.html">QStyleOption</a>&#160;<i>opt</i>)</h3><p>Use the widget's style to draw a primitive element <i>pe</i>
specified by <a href="qstyleoption.html">QStyleOption</a>
<i>option</i>.</p>
<p><b>See also</b> <a href="qstyle.html#drawPrimitive">QStyle.drawPrimitive</a>().</p>


<h3 class="fn"><a name="style" /><a href="qstyle.html">QStyle</a> QStylePainter.style (<i>self</i>)</h3><p>Return the current style used by the <a href="qstylepainter.html">QStylePainter</a>.</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;snapshot-4.9.5-9eb6aac99275 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.3</td></tr></table></div></address></body></html>